// 表单查看
<template>
  <div class="form-container card">
    <el-form
      class="form"
      ref="operaForm"
      :model="operaForm"
      label-width="100px"
    >
      <template>
        <el-form-item v-for="item in operaForm" :key="item.id" :prop="item.prop" :label="item.label">
          <template v-if="item.what !== undefined">
            <el-input
              v-if="item.prop === 'WGR'"
              v-model="operaInfo.case[item.what].WGR"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'weight_before'"
              v-model="operaInfo.case[item.what].weight_before"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'weight_after'"
              v-model="operaInfo.case[item.what].weight_after"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'outletTemperature'"
              v-model="operaInfo.case[item.what].outletTemperature"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'inletTemperature'"
              v-model="operaInfo.case[item.what].inletTemperature"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'desc'"
              v-model="operaInfo.case[item.what].desc"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'norms'"
              v-model="operaInfo.case[item.what].norms"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'type'"
              v-model="operaInfo.case[item.what].type"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else-if="item.prop === 'amount'"
              v-model="operaInfo.case[item.what].amount"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
            <el-input
              v-else
              v-model="operaInfo[item.prop]"
              :placeholder="item.placeholder"
              @input="change($event)"
            />
          </template>
          <el-input
            v-else
            v-model="operaInfo[item.prop]"
            :placeholder="item.placeholder"
            @input="change($event)"
          />
        </el-form-item>
      </template>
    </el-form>
    <!-- 下面是按钮 -->
    <div class="btn">
      <!-- 管理员不可编辑 改成role3 -->
      <el-button type="primary" @click="changeInfo">提交</el-button>
      <el-button @click="returnPage">返回</el-button>
    </div>
  </div>
</template>

<script>
// import Bus from '@/utils/bus.js'
import { AddOilone, UpdateOilone, AddOileight, UpdateOileight, UpdateSys, AddImpreg, UpdateFrame } from '@/api/dipping.js'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      operaForm: {},
      operaInfo: {},
      // 哪个表单
      kind: '',
      // 哪个操作
      handle: ''
      // ImpregnationSystem: {
      //   _id: '',
      //   case: [
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     },
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     },
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     },
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     },
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     },
      //     {
      //       _id: '',
      //       amount: '',
      //       desc: '',
      //       weight_before: '',
      //       weight_after: '',
      //       WGR: '',
      //       outletTemperature: '',
      //       inletTemperature: '',
      //       type: '',
      //       norms: ''
      //     }
      //   ]
      // }
    }
  },
  computed: {},
  watch: {},
  created () {
    // 接收路由传过来的info和kind
    // console.log(this.$route.query.handle)
    const { handle, kind } = this.$route.query
    // console.log('kind', kind)
    // console.log('handle', handle)
    this.kind = kind// 是哪个tabs
    this.handle = handle
    if (handle === '编辑') {
      const info = this.$route.query.info
      console.log('info', info) //  有数据
      // this.operaInfo = info
      // console.log('operaInfo', this.operaInfo.target)
      switch (this.kind) {
        case 'frame1':
          // this.operaInfo.case = this.ImpregnationSystem.case
          this.operaInfo.case = info.case
          this.operaInfo.case[1] = null
          this.operaInfo.case[2] = null
          this.operaInfo.case[3] = null
          this.operaInfo.case[4] = null
          this.operaInfo.case[5] = null
          this.operaInfo.case[0]._id = info.case[0]._id
          this.operaInfo._id = info._id
          console.log('到这里了frame1', this.operaInfo)
          break
        case 'frame2':
          this.operaInfo.case = info.case
          this.operaInfo.case[1]._id = info.case[1]._id
          this.operaInfo.case[0] = null
          this.operaInfo.case[2] = null
          this.operaInfo.case[3] = null
          this.operaInfo.case[4] = null
          this.operaInfo.case[5] = null
          this.operaInfo._id = info._id
          console.log('到这里了frame2', this.operaInfo)
          break
        case 'frame3':
          this.operaInfo.case = info.case
          this.operaInfo.case[2]._id = info.case[2]._id
          this.operaInfo.case[1] = null
          this.operaInfo.case[0] = null
          this.operaInfo.case[3] = null
          this.operaInfo.case[4] = null
          this.operaInfo.case[5] = null
          this.operaInfo._id = info._id
          console.log('到这里了frame2', this.operaInfo)
          break
        case 'frame4':
          this.operaInfo.case = info.case
          this.operaInfo.case[3]._id = info.case[3]._id
          this.operaInfo.case[1] = null
          this.operaInfo.case[2] = null
          this.operaInfo.case[0] = null
          this.operaInfo.case[4] = null
          this.operaInfo.case[5] = null
          this.operaInfo._id = info._id
          console.log('到这里了frame2', this.operaInfo)
          break
        case 'frame5':
          this.operaInfo.case = info.case
          this.operaInfo.case[4]._id = info.case[4]._id
          this.operaInfo.case[1] = null
          this.operaInfo.case[2] = null
          this.operaInfo.case[3] = null
          this.operaInfo.case[0] = null
          this.operaInfo.case[5] = null
          this.operaInfo._id = info._id
          console.log('到这里了frame2', this.operaInfo)
          break
        case 'frame6':
          this.operaInfo.case = info.case
          this.operaInfo.case[5]._id = info.case[5]._id
          this.operaInfo.case[1] = null
          this.operaInfo.case[2] = null
          this.operaInfo.case[3] = null
          this.operaInfo.case[4] = null
          this.operaInfo.case[0] = null
          this.operaInfo._id = info._id
          console.log('到这里了frame2', this.operaInfo)
          break
        default:
          console.log('到这里了default')
          this.operaInfo = info
          break
      }
    } else if (handle === '创建') {
      // this.operaInfo = []
      console.log('到这里了3')
      // if (this.kind === 'frame1') {
      //   this.operaInfo.case = this.ImpregnationSystem.case
      // } else {
      this.operaInfo = {} // 绝对不能赋一个空数组 要给一个空对象 否则接收不到后端传不来的值 后端传的是对象 上面data里是{}
      // }
    } else if (handle === '查看') {
      console.log('到这里了4')
      const info = this.$route.query.info
      this.operaInfo = info
      // console.log(info)
    }
    this.getOperaForm()
  },
  mounted () {},
  methods: {
    change (e) {
      this.$forceUpdate()
    },
    // 修改或提交表单
    changeInfo () {
      // console.log('this.operaForm', this.operaForm)
      // console.log('this.operaInfo', this.operaInfo)
      switch (this.kind) {
        case 'hotOilone':
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
            } else if (this.operaForm[i].type === 'float') {
              this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
            }
          }
          console.log(this.operaInfo)
          console.log(this.handle)
          if (this.handle === '创建') {
            AddOilone(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateOilone(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'hotOileight' :
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
            } else if (this.operaForm[i].type === 'float') {
              this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
            }
          }
          console.log(this.operaInfo)
          console.log(this.handle)
          if (this.handle === '创建') {
            AddOileight(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateOileight(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'eachProcessTime' :
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
            } else if (this.operaForm[i].type === 'float') {
              this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
            }
          }
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateSys(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'operationSum' :
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
            } else if (this.operaForm[i].type === 'float') {
              this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
            }
          }
          console.log(this.operaInfo)
          console.log(this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateSys(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame1' :
          console.log('case frame1 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame2' :
          console.log('case frame2 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame3' :
          console.log('case frame3 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame4' :
          console.log('case frame4 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame5' :
          console.log('case frame5 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
        case 'frame6' :
          console.log('case frame6 :', this.operaInfo)
          for (let i = 0; i < this.operaForm.length; i++) { // 先把数据的格式强制转换为int和float
            if (this.operaForm[i].type === 'int') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                this.operaInfo.case[this.operaForm[i].what].amount = parseInt(this.operaInfo.case[this.operaForm[i].what].amount)
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 1')
                this.operaInfo[this.operaForm[i].prop] = parseInt(this.operaInfo[this.operaForm[i].prop])
              }
            } else if (this.operaForm[i].type === 'float') {
              if (this.operaForm[i].what !== undefined) {
                // console.log(this.operaForm[i].what)
                // this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop] = parseFloat(this.operaInfo.case[this.operaForm[i].what][this.operaForm[i].prop])
                switch (this.operaForm[i].prop) {
                  case 'WGR':
                    // console.log('一开始', this.operaInfo.case[this.operaForm[i].what].WGR)
                    this.operaInfo.case[this.operaForm[i].what].WGR = parseFloat(this.operaInfo.case[this.operaForm[i].what].WGR)
                    // console.log('WGR', this.operaInfo.case[this.operaForm[i].what].WGR)
                    break
                  case 'inletTemperature':
                    // console.log('inletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].inletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].inletTemperature)
                    break
                  case 'outletTemperature':
                    // console.log('outletTemperature')
                    this.operaInfo.case[this.operaForm[i].what].outletTemperature = parseFloat(this.operaInfo.case[this.operaForm[i].what].outletTemperature)
                    break
                  case 'weight_after':
                    // console.log('weight_after')
                    this.operaInfo.case[this.operaForm[i].what].weight_after = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_after)
                    break
                  case 'weight_before':
                    // console.log('weight_before')
                    this.operaInfo.case[this.operaForm[i].what].weight_before = parseFloat(this.operaInfo.case[this.operaForm[i].what].weight_before)
                    break
                }
                // console.log(this.operaInfo.case[this.operaForm[i].what])
                // console.log(this.operaForm[i].prop)
              } else {
                console.log('else 2')
                this.operaInfo[this.operaForm[i].prop] = parseFloat(this.operaInfo[this.operaForm[i].prop])
              }
            }
          }
          console.log('operaInfo', this.operaInfo)
          // console.log('handle', this.handle)
          if (this.handle === '创建') {
            AddImpreg(this.operaInfo).then(res => {
              console.log(res)
              if (res.data.code === 1000) {
                this.$message.success('创建成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          } else if (this.handle === '编辑') {
            UpdateFrame(this.operaInfo).then(res => {
              console.log('编辑', res)
              if (res.data.code === 1000) {
                this.$message.success('编辑成功')
                // this.returnPage()
              }
            }).catch(err => {
              console.log(err)
            })
          }
          break
      }
      // sessionStorage.setItem('dipactiveName', this.kind) // 点提交的时候自动存一下当前的kind
      // this.$router.go(-1) // 退回上一个页面
      this.returnPage()
    },
    // 返回上一页
    returnPage () {
      // history.back(-1)
      // Bus.$emit('activeName', this.kind)

      // 保存当前标签页名称 返回之后还在当前标签页而不是在初始标签页 点击返回的时候session里显示的dipactiveName是刚离开的(点返回的)
      sessionStorage.setItem('dipactiveName', this.kind)
      this.$router.go(-1)
    },
    // 显示dialog中的空信息 相当于空表 里面有placehoder
    // 获取那个kind的表 赋给operform 因为这表是创建 编辑 要提交给后端的表单 所以要带上type属性指明float还是string类型
    getOperaForm () { // 当创建功能出现问题的时候  去mock里的form里面加上type属性 设置float和string 而不是去asset的Operaform中找
      this.$axios.get(`http://127.0.0.1:7002/${this.kind}OperaForm`).then(res => {
        this.operaForm = res.data.tableData
        console.log('operaForm', res.data.tableData)
      })
    }
  }
}
</script>

<style scoped lang="">
.form {
  padding: 40px 0;
}
.btn {
  text-align: right;
}
.el-form-item {
  /* width: 100px; */
  display: inline-block !important;
}
</style>
